home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / X11R4 / cmds / X / os / sprite / RCS / osinit.c,v < prev    next >
Encoding:
Text File  |  1991-01-11  |  4.1 KB  |  197 lines

  1. head     1.2;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.2
  10. date     91.01.10.20.27.40;  author shirriff;  state Exp;
  11. branches ;
  12. next     1.1;
  13.  
  14. 1.1
  15. date     90.02.14.19.25.24;  author tve;  state Exp;
  16. branches ;
  17. next     ;
  18.  
  19.  
  20. desc
  21. @Original X11R4 distribution
  22. @
  23.  
  24.  
  25. 1.2
  26. log
  27. @Changed log open from "a+" to "a" because our syslog only allows one
  28. reader.
  29. @
  30. text
  31. @/***********************************************************
  32. Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
  33. and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
  34.  
  35.                         All Rights Reserved
  36.  
  37. Permission to use, copy, modify, and distribute this software and its 
  38. documentation for any purpose and without fee is hereby granted, 
  39. provided that the above copyright notice appear in all copies and that
  40. both that copyright notice and this permission notice appear in 
  41. supporting documentation, and that the names of Digital or MIT not be
  42. used in advertising or publicity pertaining to distribution of the
  43. software without specific, written prior permission.  
  44.  
  45. DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  46. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  47. DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  48. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  49. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  50. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  51. SOFTWARE.
  52.  
  53. ******************************************************************/
  54. /* $XConsortium: osinit.c,v 1.28 89/12/18 15:41:25 rws Exp $ */
  55. #include "os.h"
  56. #include "opaque.h"
  57. #undef NULL
  58. #ifdef NDBM
  59. #include <ndbm.h>
  60. #else
  61. #include <dbm.h>
  62. #endif
  63. #undef NULL
  64. #include <stdio.h>
  65. #include "Xos.h"
  66. #ifndef MAXPATHLEN
  67. /*
  68.  * just to get MAXPATHLEN.  Define it elsewhere if you need to
  69.  * avoid these files.
  70.  */
  71. #include <sys/param.h>
  72. #endif
  73.  
  74. #ifndef SYSV
  75. #include <sys/resource.h>
  76. #endif
  77.  
  78. #ifndef ADMPATH
  79. #define ADMPATH "/usr/adm/X%smsgs"
  80. #endif
  81.  
  82. #ifdef NDBM
  83. DBM     *rgb_dbm = (DBM *)NULL;
  84. #else
  85. int    rgb_dbm = 0;
  86. #endif
  87. extern char *display;
  88. #ifndef SYSV
  89. int limitDataSpace = -1;
  90. int limitStackSpace = -1;
  91. #endif
  92.  
  93. OsInit()
  94. {
  95.     static Bool been_here = FALSE;
  96.     char fname[MAXPATHLEN];
  97.  
  98. #ifdef macII
  99.     set42sig();
  100. #endif
  101.  
  102.     /* hack test to decide where to log errors */
  103.  
  104.     if (!been_here) {
  105.     if (write (2, fname, 0)) 
  106.     {
  107.         long t; 
  108.         char *ctime();
  109.         FILE *err;
  110.         fclose(stdin);
  111.         fclose(stdout);
  112.         sprintf (fname, ADMPATH, display);
  113.         /*
  114.          * uses stdio to avoid os dependencies here,
  115.          * a real os would use
  116.           *  open (fname, O_WRONLY|O_APPEND|O_CREAT, 0666)
  117.          */
  118.         if (!(err = fopen (fname, "a")))
  119.         err = fopen ("/dev/null", "w");
  120.         if (err && (fileno(err) != 2)) {
  121.         dup2 (fileno (err), 2);
  122.         fclose (err);
  123.         }
  124. #ifdef SYSV        /* yes, even though it is 4.2bsd.... */
  125.         {
  126.         static char buf[BUFSIZ];
  127.         setvbuf (stderr, buf, _IOLBF, BUFSIZ);
  128.         }
  129. #else
  130.         setlinebuf(stderr);
  131. #endif
  132.         time (&t);
  133.         fprintf (stderr, "start %s", ctime(&t));
  134.     }
  135.  
  136.     if (getpgrp (0) == 0)
  137.         setpgrp (0, getpid ());
  138.  
  139.  
  140. #ifndef SYSV
  141. #if !defined(AIXrt) && !defined(AIX386)
  142.     if (limitDataSpace >= 0)
  143.     {
  144.         struct rlimit    rlim;
  145.  
  146.         if (!getrlimit(RLIMIT_DATA, &rlim))
  147.         {
  148.         if ((limitDataSpace > 0) && (limitDataSpace < rlim.rlim_max))
  149.             rlim.rlim_cur = limitDataSpace;
  150.         else
  151.             rlim.rlim_cur = rlim.rlim_max;
  152.         (void)setrlimit(RLIMIT_DATA, &rlim);
  153.         }
  154.     }
  155.     if (limitStackSpace >= 0)
  156.     {
  157.         struct rlimit    rlim;
  158.  
  159.         if (!getrlimit(RLIMIT_STACK, &rlim))
  160.         {
  161.         if ((limitStackSpace > 0) && (limitStackSpace < rlim.rlim_max))
  162.             rlim.rlim_cur = limitStackSpace;
  163.         else
  164.             rlim.rlim_cur = rlim.rlim_max;
  165.         (void)setrlimit(RLIMIT_STACK, &rlim);
  166.         }
  167.     }
  168. #endif
  169. #endif
  170.     been_here = TRUE;
  171.     }
  172.  
  173.     if (!rgb_dbm)
  174.     {
  175. #ifdef NDBM
  176.     rgb_dbm = dbm_open(rgbPath, 0, 0);
  177. #else
  178.     if (dbminit(rgbPath) == 0)
  179.         rgb_dbm = 1;
  180. #endif
  181.     if (!rgb_dbm)
  182.         ErrorF( "Couldn't open RGB_DB '%s'\n", rgbPath );
  183.     }
  184. }
  185. @
  186.  
  187.  
  188. 1.1
  189. log
  190. @Initial revision
  191. @
  192. text
  193. @d88 1
  194. a88 1
  195.         if (!(err = fopen (fname, "a+")))
  196. @
  197.